<?php
namespace BP\GPM;
require_once("java/io/IOException.php");
class Glo {
	public static function getOSModel () 
	{
		return ;
	}
	public static function getIsEnable_DingDing () 
	{
		$corpid = SystemConfig::getDing_CorpID();
		$corpsecret = SystemConfig::getDing_CorpSecret();
		if (($DataType->IsNullOrEmpty($corpid) || $DataType->IsNullOrEmpty($corpsecret)))
		{
			return  FALSE ;
		}
		return  TRUE ;
	}
	public static function getIsEnable_WeiXin () 
	{
		$corpid = SystemConfig::getWX_CorpID();
		$corpsecret = SystemConfig::getWX_AppSecret();
		if (($DataType->IsNullOrEmpty($corpid) || $DataType->IsNullOrEmpty($corpsecret)))
		{
			return  FALSE ;
		}
		return  TRUE ;
	}
	public static function DoInstallDataBase () 
	{
		$al = NULL;
		$info = "BP.En.Entity";
		$al = $BP->En->ClassFactory->GetObjects($info);
		foreach ($al as $obj) 		{
			$en = NULL;
			$en = ( ($obj instanceof Entity) ? $obj : NULL );
			if (($en == NULL))
			{
				continue;
			}
			if (($en == NULL))
			{
				continue;
			}
			if ($en->contains("BP.Port."))
			{
				continue;
			}
			if (($en->contains("BP.GPM.") ==  FALSE ))
			{
				continue;
			}
			$table = NULL;
			try 
			{
				$table = $en->getEnMap()->getPhysicsTable();
				if (($table . NULL))
				{
					continue;
				}
				if (($en->getEnMap()->getPhysicsTable()->toLowerCase()->contains("demo_") ==  TRUE ))
				{
					continue;
				}
			}
			catch (\Exception $e)
			{
				continue;
			}
			switch ($table) {
				case "WF_EmpWorks":
				case "WF_GenerEmpWorkDtls":
				case "WF_GenerEmpWorks":
					continue;
				case "Sys_Enum":
					$en->CheckPhysicsTable();
					break;
				default:
					$en->CheckPhysicsTable();
					break;
			}
			$en->setPKVal("123");
			try 
			{
				$en->RetrieveFromDBSources();
			}
			catch (\RuntimeException $ex)
			{
				$Log->DebugWriteWarning($ex->getMessage());
				$en->CheckPhysicsTable();
			}
		}
		$xmls = new EnumInfoXmls();
		$xmls->RetrieveAll();
		foreach ($xmls->ToJavaList() as $xml) 		{
			$ses = new SysEnums();
			$ses->RegIt($xml->getKey(), $xml->getVals());
		}
		$sqlscript = ($SystemConfig->getPathOfWebApp() . "/GPM/SQLScript/Port_Inc_CH_BPM.sql");
		DBAccess->RunSQLScript($sqlscript);
		if ((DBAccess->IsExitsObject("GPM_AppSort") ==  TRUE ))
		{
			$sqlscript = ($SystemConfig->getPathOfWebApp() . "/GPM/SQLScript/InitPublicData.sql");
			DBAccess->RunSQLScript($sqlscript);
		}
		$sqlscript = ($SystemConfig->getPathOfWebApp() . "/GPM/SQLScript/MSSQL_GPM_VIEW.sql");
		if ((SystemConfig::getAppCenterDBType() == $DBType->MySQL))
		{
			$sqlscript = ($SystemConfig->getPathOfWebApp() . "/GPM/SQLScript/MySQL_GPM_VIEW.sql");
		}
		if ((SystemConfig::getAppCenterDBType() == $DBType->Oracle))
		{
			$sqlscript = ($SystemConfig->getPathOfWebApp() . "/GPM/SQLScript/Oracle_GPM_VIEW.sql");
		}
		DBAccess->RunSQLScriptGo($sqlscript);
		$depts = Depts::constructor__();
		$depts->RetrieveAll();
		foreach ($depts->ToJavaList() as $dept) 		{
			$dept->GenerNameOfPath();
		}
	}
	public static function IsCanDoIt ($ctrlObj, $cw, $empID) // [String ctrlObj, BP.GPM.CtrlWay cw, String empID]
	{
		$n = 0;
		$sql = "";
		switch ($cw) {
			case $AnyOne:
				return  TRUE ;
			case $ByStation:
				$sql = (((("SELECT count(*) FROM GPM_ByStation WHERE RefObj='" . $ctrlObj) . "'  AND FK_Station IN (select FK_Station from  Port_DeptEmpStation WHERE FK_Emp='") . $empID) . "')");
				$n =DBAccess->RunSQLReturnValInt($sql, 0);
				break;
			case $ByDept:
				$sql = (((("SELECT count(*) FROM GPM_ByDept WHERE RefObj='" . $ctrlObj) . "'  AND FK_Dept IN (SELECT FK_Dept FROM Port_Emp WHERE No='") . $empID) . "')");
				$n =DBAccess->RunSQLReturnValInt($sql, 0);
				break;
			case $ByEmp:
				$sql = (((("SELECT count(*) FROM GPM_ByEmp WHERE RefObj='" . $ctrlObj) . "'  AND  FK_Emp='") . $empID) . "'");
				$n =DBAccess->RunSQLReturnValInt($sql, 0);
				break;
			default:
				break;
		}
		if (($n == 0))
		{
			return  FALSE ;
		}
		else
		{
			return  TRUE ;
		}
	}
}
?>
